#include <cstdio>

int n;
long long m = 1;
int a[11], b[11];

void exgcd(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1, y = 0;
		return;
	}
	exgcd(b, a % b, y, x);
	y -= a / b * x;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
	freopen("testdata.in", "r", stdin);
	freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
	freopen("CRT.in", "r", stdin);
	freopen("CRT.out", "w", stdout);
#endif
#endif

	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", &a[i], &b[i]);
		m *= a[i];
	}
	long long x, y, ans = 0;
	for (int i = 1; i <= n; ++i) {
		exgcd(m / a[i], a[i], x, y);
		ans = ((ans + m / a[i] * b[i] * x) % m + m) % m;
	}
	printf("%lld", ans);
	return 0;
}